package com.hcqc.demo.server;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hcqc.demo.mapper.UserMapper;
import com.hcqc.demo.pojo.User;
import com.hcqc.demo.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Service
public class UserServerImpl implements UserServer {
    @Autowired
    UserMapper userMapper;

    @Override
    public Result login(String username, String pwd, HttpServletRequest request) {
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.eq("USER_NAME", username);
        User user = userMapper.selectOne(queryWrapper);
        if (user!=null){
            if (user.getUSER_PWD().equals(pwd)){
                //登陆成功
                HttpSession session = request.getSession();
                session.setAttribute("USER_NAME", user.getUSER_NAME());
                return Result.success();
            }
        }
        return Result.fail("账号或密码不正确");
    }
}
